package com.daiqee.controller.support;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.daiqee.pojo.User;
import com.daiqee.vo.RestFulResultVO;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 定义公共的属性
 * 
 * E:Entity-POJO
 * S:Service
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V2.1
 * @author RichardTang 
 * @date: 2018年5月7日 下午5:52:51
 * @package com.daiqee.handler
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
public class BaseController{
	
	//用来存储受影响的结果数
	protected Integer resultNum;
	
	//是否正常执行
	protected Boolean isNormalFinish;
	
	@Autowired
	protected HttpSession 		   session;

	@Autowired
	protected ServletContext 	   application;
	
	@Autowired
	protected HttpServletRequest   request;

	@Autowired
	protected HttpServletResponse  response;

	protected ObjectMapper mapper = new ObjectMapper();
	
	protected Logger logger = Logger.getLogger(this.getClass());
	
	protected RestFulResultVO restfulResponse = new RestFulResultVO();
	
	/**
	 * 从session中获取当前用户
	 * @return 当前用户对象
	 */
	protected User getCurrentUser() {
		if(session!=null) {
			return (User) session.getAttribute("user");
		}
		User user = new User();
		user.setUserName("当前用户不存在！");
		return user;
	}
}
